import React, {Component} from 'react';
import {
    Platform,
    StyleSheet,
    Dimensions,
    PixelRatio,
    StatusBar
} from 'react-native';
const instructions = Platform.select({
    ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
    android:
        'Double tap R on your keyboard to reload,\n' +
        'Shake or press menu button for dev menu',
});

// 1) fetch
// 2） 获取屏幕的宽高
// 3） 获取最小线宽
export const Util = {
    size: {
        height: Dimensions.get('window').height,
        width: Dimensions.get('window').width,
    },
    pixel: 1 / PixelRatio.get(),
    // fetch <=>ajax
    get: function (url, successCallback, failCallback) {
        fetch(url)
            .then((response)=> response.json())
            .then((responseJson) => {
                successCallback(responseJson);
            })
            .catch((error) => {
               failCallback(error);
            });
    },
};


// iPhone X、iPhone XS
const X_WIDTH = 375;
const X_HEIGHT = 812;
// iPhone XR、iPhone XS Max
const XSMAX_WIDTH = 414;
const XSMAX_HEIGHT = 896;
const DEVICE_SIZE = Dimensions.get('window');
const { height: D_HEIGHT, width: D_WIDTH } = DEVICE_SIZE;

export const isiOS = () => Platform.OS === 'ios'

const STATUS_BAR_HEIGHT = isiOS() ? (isIphoneX ? 34 : 20) : StatusBar.currentHeight
const isIphoneX = (
    isiOS() &&
    ((D_HEIGHT === X_HEIGHT && D_WIDTH === X_WIDTH) ||
        (D_HEIGHT === X_WIDTH && D_WIDTH === X_HEIGHT)) ||
    ((D_HEIGHT === XSMAX_HEIGHT && D_WIDTH === XSMAX_WIDTH) ||
        (D_HEIGHT === XSMAX_WIDTH && D_WIDTH === XSMAX_HEIGHT))
);
export function ifIphoneX (iphoneXStyle, regularStyle) {
    if (isIphoneX) {
        return iphoneXStyle;
    } else {
        return regularStyle
    }
}
